package br.ufrpe.bsi.pvs.view.admin;

import org.jdom2.Document;

import br.ufrpe.bsi.pvs.Fachada;
import br.ufrpe.bsi.pvs.model.funcionario.Funcionario;
import br.ufrpe.bsi.pvs.view.PvsFrame;
import br.ufrpe.bsi.pvs.xml.transformer.FuncionarioXML;


public class TelaLogin extends javax.swing.JPanel {

    public static TelaLogin INSTANCE = new TelaLogin();
    
    private TelaLogin() {
        initComponents();
    }

    private void login(){
    	Funcionario f = new Funcionario();
    	f.setLogin(txtLogin.getText());
    	f.setSenha(new String (txpPasswd.getPassword()));
    	//Document doc = FuncionarioXML.parseLoginRequest(f);
		//Fachada.sendRequest(doc);
		
	}

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txtLogin = new javax.swing.JTextField();
        txpPasswd = new javax.swing.JPasswordField();
        lbLogin = new javax.swing.JLabel();

        setBackground(java.awt.Color.white);

        jLabel1.setFont(new java.awt.Font("SansSerif", 0, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pvs-logo.png"))); // NOI18N

        jPanel1.setOpaque(false);

        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(350, 250));

        txtLogin.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        txtLogin.setForeground(java.awt.Color.gray);
        txtLogin.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(205, 205, 205)), javax.swing.BorderFactory.createEmptyBorder(5, 15, 5, 15)));
        txtLogin.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtLoginFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtLoginFocusLost(evt);
            }
        });

        txpPasswd.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        txpPasswd.setForeground(java.awt.Color.gray);
        txpPasswd.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(205, 205, 205)), javax.swing.BorderFactory.createEmptyBorder(5, 15, 5, 15)));
        txpPasswd.setPreferredSize(new java.awt.Dimension(62, 27));
        txpPasswd.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txpPasswdFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txpPasswdFocusLost(evt);
            }
        });

        lbLogin.setBackground(java.awt.Color.black);
        lbLogin.setFont(new java.awt.Font("Gabriola", 0, 36)); // NOI18N
        lbLogin.setForeground(new java.awt.Color(255, 255, 255));
        lbLogin.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbLogin.setText("login");
        lbLogin.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(205, 205, 205)));
        lbLogin.setOpaque(true);
        lbLogin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbLoginMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lbLoginMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lbLoginMouseExited(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lbLogin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtLogin, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
                    .addComponent(txpPasswd, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txpPasswd, txtLogin});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(txpPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
                .addComponent(lbLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txpPasswd, txtLogin});

        jPanel1.add(jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtLoginFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtLoginFocusGained
        if (txtLogin.getText().trim().equals("user name"))
            txtLogin.setText("");
    }//GEN-LAST:event_txtLoginFocusGained

    private void txtLoginFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtLoginFocusLost
        if (txtLogin.getText().isEmpty())
            txtLogin.setText("user name");
    }//GEN-LAST:event_txtLoginFocusLost

    private void txpPasswdFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txpPasswdFocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_txpPasswdFocusGained

    private void txpPasswdFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txpPasswdFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txpPasswdFocusLost

    private void lbLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbLoginMouseClicked
        login();    	
    	PvsFrame.INSTANCE.show(TelaMenuPrincipal.INSTANCE);
    }//GEN-LAST:event_lbLoginMouseClicked

    private void lbLoginMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbLoginMouseEntered
        //lbLogin.setBackground(new Color(245, 245, 245) );
    }//GEN-LAST:event_lbLoginMouseEntered

    private void lbLoginMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbLoginMouseExited
        //lbLogin.setBackground(Color.WHITE);
    }//GEN-LAST:event_lbLoginMouseExited


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lbLogin;
    private javax.swing.JPasswordField txpPasswd;
    private javax.swing.JTextField txtLogin;
    // End of variables declaration//GEN-END:variables
}
